package leetcode.ge100;

import leetcode.lt100.TreeNode;

import java.util.ArrayList;
import java.util.List;


class Solution_114 {


    public static void main(String[] args) {
    }

    public void flatten(TreeNode root) {
        if (root == null) {
            return;
        }

        if (root.left == null) {
            flatten(root.right);
            return;
        }

        if (root.right == null) {
            flatten(root.left);
            root.right = root.left;
            root.left = null;
            return;
        }

        flatten(root.right);
        TreeNode temp = root.right;
        flatten(root.left);
        root.right = root.left;
        root.left = null;
        while (root.right != null) {
            root = root.right;
        }
        root.right = temp;
    }

}